﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.Base;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Domain.BusinessManage;
using SmartWMS.Domain.WarehouseManage;
using SmartWMS.EntityFramework;
using SmartWMS.Server.WarehouseManage.StockManagement;
using SmartWMS.Server.WarehouseManage.StockManagement.Dto;

namespace SmartWMS.API.Controllers.WarehouseManage.StockManagement
{
    /// <summary>
    /// 入库管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
	[ApiExplorerSettings(GroupName = "Warehouse")]
	public class StockController : ControllerBase
    {
        private readonly IStockServe _stockService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="stockService"></param>
        public StockController(IStockServe stockService)
        {
            _stockService = stockService;
        }


        /// <summary>
        /// 显示入库管理(分页)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Response<List<StockDto>>> GetStockList(StockSelectDto input)
        {
            try
            {
               var result = await _stockService.GetStockList(input);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 添加入库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Response<bool>> PostStockAdd(StockAdd input)
        {
            try
            {
                var InWarehouse = await _stockService.PostStockAdd(input);
                return InWarehouse;
            }
            catch (Exception)
            {

                throw;
            }
        }


     


        /// <summary>
        /// 获取采购列表
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<List<ProcureManagementCode>> GetProcureManagementList()
        {
            try
            {
                var list = await _stockService.GetProcureManagementList();
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 入库单详细
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<InWarehouseListDto> GetInWarehouseList(KeyEntity Id)
        {
            try
            {
                var InWareList = await _stockService.GetInWarehouseList(Id);
                return InWareList;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<List<ProductDtoInWar>> GetProductDtojwz(KeyEntity Id)
        {
            try
            {
                var InWareList = await _stockService.GetProductDtojwz(Id);
                return InWareList;
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 反填查询入仓信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<StockAdd> GetBackFill(KeyEntity Id)
        {
            try
            {
                var list = await _stockService.GetBackFill(Id);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 反填入库详细
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<InWarehouseDetailAdd>> GetinWareDetailListBackfill(KeyEntity Id)
        {
            try
            {
                var list = await _stockService.GetinWareDetailListBackfill(Id);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 删除入库信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Response<bool>> DeletInWare(KeyEntity Id)
        {
            try
            {
                var InWarehouseList = await _stockService.DeletInWare(Id);
                return InWarehouseList;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改入库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Response<bool>> PostInWareUpdate(StockAdd input)
        {
            try
            {
                var result  =  await _stockService.PostInWareUpdate(input);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 批量删除入库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeleteBatches(List<StockAdd> input)
        {
            try
            {
                var List = await _stockService.DeleteBatches(input);
                return List;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改入库审核状态
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Response<bool>> GetInWarehouseListState(InWarehouseSteatDto input)
        {
            try
            {
                var list = await _stockService.GetInWarehouseListState(input);
                return list;

            }
            catch (Exception)
            {

                throw;
            }
        }


    }
}
